package sdk

import (
	"inkjet168x-sdk-go/sdk/protocol/workcode"
)

// WorkcodeSDK 命令包协议SDK
type WorkcodeSDK struct{}

// NewWorkcodeSDK 创建新的命令包SDK实例
func NewWorkcodeSDK() *WorkcodeSDK {
	return &WorkcodeSDK{}
}

// NewWorkcodeProtocol 创建新的命令包协议实例
func (ws *WorkcodeSDK) NewWorkcodeProtocol() *WorkcodeProtocol {
	return &WorkcodeProtocol{
		builder: workcode.NewBuilder(),
	}
}

// CreateWorkcodeProtocol 创建命令包协议并返回二进制数据
func (ws *WorkcodeSDK) CreateWorkcodeProtocol(protocol *WorkcodeProtocol) ([]byte, error) {
	// 构建协议
	builtProtocol, err := protocol.builder.Build()
	if err != nil {
		return nil, err
	}
	
	// 序列化为二进制数据
	return builtProtocol.Marshal()
}

// WorkcodeProtocol 命令包协议包装器
type WorkcodeProtocol struct {
	builder *workcode.Builder
}

// SetSequence 设置序列号
func (wp *WorkcodeProtocol) SetSequence(sequence uint16) *WorkcodeProtocol {
	wp.builder.SetSequence(sequence)
	return wp
}

// SetCommandCode 设置命令代码
func (wp *WorkcodeProtocol) SetCommandCode(code uint32) *WorkcodeProtocol {
	wp.builder.SetCommandCode(code)
	return wp
}

// SetCommandParam 设置命令参数
func (wp *WorkcodeProtocol) SetCommandParam(param uint32) *WorkcodeProtocol {
	wp.builder.SetCommandParam(param)
	return wp
}

// SetCommand 同时设置命令代码和参数
func (wp *WorkcodeProtocol) SetCommand(code, param uint32) *WorkcodeProtocol {
	wp.builder.SetCommand(code, param)
	return wp
}